1 00:00:00,170 --> 00:00:02,780 Now let's start adding some code to our shop. 2 00:00:02,780 --> 00:00:05,560 And I'm going to start on the client side here, the gooey side. 3 00:00:05,570 --> 00:00:13,850 Let's go to starter GUI screen GUI shop frame, and then here's our shop script. 4 00:00:13,850 --> 00:00:15,350 Let's open that up. 5 00:00:15,590 --> 00:00:17,600 I want to add two variables to this script. 6 00:00:17,600 --> 00:00:19,040 We're not quite at the top. 7 00:00:19,040 --> 00:00:19,790 That's the top. 8 00:00:19,790 --> 00:00:21,080 That's line one. 9 00:00:21,080 --> 00:00:24,130 Let's go and look at about line ten. 10 00:00:24,140 --> 00:00:28,580 We have some variables for the selected item, right? 11 00:00:28,580 --> 00:00:33,080 So if you have cabin or fence, you have the image, the name, the price. 12 00:00:33,080 --> 00:00:37,550 But we need to add the type, whether it's a house type or a fence type. 13 00:00:37,850 --> 00:00:46,580 So I'll do local preview type equals shop frame to by frame. 14 00:00:46,820 --> 00:00:47,510 What was that like? 15 00:00:47,510 --> 00:00:47,960 Property. 16 00:00:47,990 --> 00:00:49,940 There it is, property type label. 17 00:00:50,480 --> 00:00:51,410 There we go. 18 00:00:51,410 --> 00:00:53,510 And we're going to need another variable. 19 00:00:53,510 --> 00:00:55,130 I'm going to put it at the bottom. 20 00:00:55,460 --> 00:00:57,620 And this is for the player data. 21 00:00:58,280 --> 00:01:01,500 Whoops, we'll call it player data. 22 00:01:01,500 --> 00:01:04,570 We're going to initialize it to nil When we open the shop. 23 00:01:04,570 --> 00:01:05,610 It's going to be server side. 24 00:01:05,610 --> 00:01:06,960 We're going to send a remote event. 25 00:01:06,960 --> 00:01:12,120 Player data is going to get the data for the player about the property it owns. 26 00:01:12,120 --> 00:01:17,610 So we don't accidentally sell them a house when he doesn't own a lot or sell them the same house twice. 27 00:01:17,610 --> 00:01:19,170 We don't want to do that. 28 00:01:19,320 --> 00:01:25,200 So in the preview item, when we select an item on the right, it's going to show the values of that 29 00:01:25,200 --> 00:01:25,920 item. 30 00:01:26,040 --> 00:01:33,750 Let's add our preview type stuff and it's going to be of type text on the button. 31 00:01:33,750 --> 00:01:35,550 We are going to have. 32 00:01:35,910 --> 00:01:36,840 Let's take a look. 33 00:01:37,540 --> 00:01:39,130 Items frame. 34 00:01:39,400 --> 00:01:40,330 Here's a button. 35 00:01:40,330 --> 00:01:41,560 So we have two buttons. 36 00:01:42,100 --> 00:01:43,030 Prop type. 37 00:01:43,030 --> 00:01:45,700 So it's going to be a prop type and that's a string value. 38 00:01:45,700 --> 00:01:54,880 So it'll be prop type value, prop type dot value, and then we'll know whether it's a house or a fence. 39 00:01:54,910 --> 00:01:59,200 Also, we have preview item, we have clear fields. 40 00:01:59,200 --> 00:02:04,390 So something happens where we got to clear the fields out like they make a purchase or they close the 41 00:02:04,390 --> 00:02:05,770 window, things like that. 42 00:02:05,770 --> 00:02:12,760 Let's do a control C, control V, and I'm just going to call this instead of preview price preview 43 00:02:12,760 --> 00:02:13,450 prop type. 44 00:02:15,590 --> 00:02:17,990 Another thing we're going to look at is. 45 00:02:18,710 --> 00:02:19,400 Our shop. 46 00:02:19,480 --> 00:02:20,480 Re right. 47 00:02:20,480 --> 00:02:22,220 This is how we open our window up. 48 00:02:22,220 --> 00:02:26,570 A server event happens and it says, Hey, open up the GUI for the player. 49 00:02:26,780 --> 00:02:33,200 But since we're on the server side coming to the client side, we can send our property data. 50 00:02:33,230 --> 00:02:34,980 I'm just going to call that data. 51 00:02:35,000 --> 00:02:36,170 We haven't done it yet. 52 00:02:36,170 --> 00:02:39,530 That's going to be over on server side, but we will. 53 00:02:39,530 --> 00:02:46,910 And then I'm going to get my player data variable player data variable, set it equal to the data that 54 00:02:46,910 --> 00:02:50,570 came over from the remote event from the server side. 55 00:02:52,460 --> 00:02:55,580 And we want to do a little bit of error checking to. 56 00:02:56,500 --> 00:02:58,780 So notice how we did this is owned. 57 00:02:58,810 --> 00:03:03,290 We check to see if the player had the item, whether it was in the backpack or they're holding it. 58 00:03:03,310 --> 00:03:04,480 I'm going to change this. 59 00:03:04,480 --> 00:03:07,960 I'm going to change this to can buy. 60 00:03:08,290 --> 00:03:13,190 Let's also add a prop type here in the parameters right after item. 61 00:03:13,210 --> 00:03:15,520 I'm going to say prop type. 62 00:03:15,850 --> 00:03:18,340 We're not going to check the character. 63 00:03:18,370 --> 00:03:18,570 Right. 64 00:03:18,640 --> 00:03:19,870 Because it's not a tool. 65 00:03:20,920 --> 00:03:23,530 And what should we do here? 66 00:03:23,560 --> 00:03:27,010 We don't need to check to see if the item is owned that way either. 67 00:03:27,370 --> 00:03:33,030 Well, we do need to do is check if not player data. 68 00:03:33,040 --> 00:03:49,180 So if there's no player data or not player data dot has lot, then let's grab this line Control C, 69 00:03:49,210 --> 00:03:50,820 we're going to give them a message. 70 00:03:50,830 --> 00:03:53,650 This shows up on top of the shop frame. 71 00:03:53,650 --> 00:03:55,990 Let's leave a message that makes more sense. 72 00:03:56,180 --> 00:04:07,250 Let's say player does not have a lot exclamation mark and then we're going to return False. 73 00:04:07,280 --> 00:04:08,930 They cannot buy a lot. 74 00:04:08,960 --> 00:04:14,030 They either had they had no data or they didn't have a lot. 75 00:04:15,660 --> 00:04:17,250 I'm going to get rid of this. 76 00:04:18,930 --> 00:04:20,580 And now I have to look at our type. 77 00:04:20,580 --> 00:04:23,610 So we got down to the point where we do have a lot. 78 00:04:23,640 --> 00:04:29,370 We're going to say if prop type equals equals, and I'm going to hardcode these, I'm going to use string 79 00:04:29,370 --> 00:04:30,030 literals. 80 00:04:30,030 --> 00:04:37,110 You might want to have a list of of proper prop types that you can draw from some enum, but I didn't 81 00:04:37,110 --> 00:04:41,310 really cover that in this class, so we'll just type in fence. 82 00:04:41,310 --> 00:04:54,630 So if it's a prop type fence, if not player data dot fence, then print. 83 00:04:55,050 --> 00:05:00,480 We can buy a fence. 84 00:05:01,200 --> 00:05:01,460 All right. 85 00:05:01,500 --> 00:05:04,980 So if we hold on, let me just finish this return. 86 00:05:04,980 --> 00:05:05,430 True. 87 00:05:05,430 --> 00:05:10,680 So if the prop type that we're purchasing is of type fence, we're going to check to see if they have 88 00:05:10,680 --> 00:05:11,070 a fence. 89 00:05:11,070 --> 00:05:14,430 If they don't have a fence, if not fence, we can buy a fence. 90 00:05:14,430 --> 00:05:15,550 So we're going to return. 91 00:05:15,550 --> 00:05:16,120 True. 92 00:05:16,150 --> 00:05:18,790 We're going to say can buy is true. 93 00:05:19,060 --> 00:05:25,000 We don't need to leave a message on the on the shop because it made sense. 94 00:05:25,120 --> 00:05:26,320 Everything was fine. 95 00:05:26,740 --> 00:05:28,840 I'm going to do another if statement here. 96 00:05:28,870 --> 00:05:31,990 I probably should have just done an if else but I'll do an if statement. 97 00:05:31,990 --> 00:05:42,400 If player data dot fence equals equals the item, let's let them know that they already owned the item, 98 00:05:42,400 --> 00:05:43,790 we're going to cancel the purchase. 99 00:05:43,790 --> 00:05:55,000 So I'm going to say message label dot text equals already owns that item, exclamation. 100 00:05:55,000 --> 00:05:58,540 And then I'm just going to return a false Don't buy it. 101 00:05:58,840 --> 00:06:00,640 Well, we can't buy it, right? 102 00:06:00,640 --> 00:06:01,930 We're going to return a false. 103 00:06:01,960 --> 00:06:10,420 Let's go ahead and copy this for the House Control C and we'll go down one line, Control V, Let's 104 00:06:10,420 --> 00:06:12,340 change all this fence stuff to house stuff. 105 00:06:12,340 --> 00:06:17,970 So if the property type is of type house, check to see if there's house data. 106 00:06:19,110 --> 00:06:21,600 If there's not house data, we can definitely buy a house. 107 00:06:21,630 --> 00:06:24,870 Well, we're also going to check for money, but we're going to do that server side. 108 00:06:24,900 --> 00:06:26,490 These are preliminary checks. 109 00:06:26,490 --> 00:06:27,630 So this is true. 110 00:06:27,630 --> 00:06:30,090 It's going to say, All right, we're going to go to server side. 111 00:06:30,210 --> 00:06:34,950 We need to change this to check for player data house. 112 00:06:34,980 --> 00:06:40,290 If the house is the item that we're trying to buy up, already owns that item. 113 00:06:40,290 --> 00:06:41,820 So we don't have to change anything here. 114 00:06:41,820 --> 00:06:43,350 We're going to deny them. 115 00:06:43,560 --> 00:06:48,300 And let's take a look down here where we're getting this nasty red line. 116 00:06:48,300 --> 00:06:50,640 We have an error is owned. 117 00:06:50,670 --> 00:06:56,160 We don't want is owned, we want can buy and we don't want it to be not is owned. 118 00:06:56,190 --> 00:07:00,720 We want it to be just can buy. 119 00:07:01,770 --> 00:07:10,050 Another thing, we're going to send the prop type, so we'll do the preview type, which is the prop 120 00:07:10,080 --> 00:07:15,600 type text into can own because we've got to check to see if it's house or fence. 121 00:07:15,870 --> 00:07:21,030 Here we're checking to see if we have enough points, but we're doing the subtracting on the server 122 00:07:21,030 --> 00:07:21,570 side. 123 00:07:21,570 --> 00:07:30,240 So now we'll get down here to shop and we need to send the property type, right? 124 00:07:30,240 --> 00:07:36,410 So we have that in preview type dot text. 125 00:07:36,420 --> 00:07:38,190 So we make two lines for this. 126 00:07:38,190 --> 00:07:38,730 Yeah. 127 00:07:38,730 --> 00:07:39,390 Let's go ahead. 128 00:07:39,390 --> 00:07:42,180 You can leave it all on one, but I want you to be able to see it. 129 00:07:43,290 --> 00:07:43,560 All right. 130 00:07:43,560 --> 00:07:44,730 That looks pretty good. 131 00:07:45,270 --> 00:07:47,100 Let's check this out. 132 00:07:47,130 --> 00:07:54,690 We're not getting any lot data yet from the server up to our UI, but we can still check for errors. 133 00:07:54,720 --> 00:07:57,810 Let's go to the view output window. 134 00:07:57,810 --> 00:08:02,290 Oh, and we still have our property test script putting houses out there. 135 00:08:02,290 --> 00:08:05,800 We're going to have to disable that, although it does look kind of cool. 136 00:08:05,830 --> 00:08:07,510 Let's go to our owner. 137 00:08:07,510 --> 00:08:08,770 Hit the little bell. 138 00:08:08,920 --> 00:08:09,910 Dang. 139 00:08:09,910 --> 00:08:15,730 And this should say player does not have lot because we don't have the lot information on the client. 140 00:08:15,730 --> 00:08:22,930 I'm going to hit my cabin and hit play or by boom player does not have lot and there's no red nasty 141 00:08:22,960 --> 00:08:26,230 red down there so it doesn't look like we have any errors so far. 142 00:08:26,230 --> 00:08:27,550 Let's hit this again. 143 00:08:27,550 --> 00:08:29,350 Let's hit fence. 144 00:08:29,980 --> 00:08:31,990 By player does not have lot. 145 00:08:32,740 --> 00:08:33,010 All right. 146 00:08:33,010 --> 00:08:34,240 That's looking pretty good.